#ifndef SENSOR_USER_H
#define SENSOR_USER_H

#define USER_RESET_SENSOR 			0x00		// w [0] 直连传感器，控制复位引脚
#define USER_START_TRAINING 		0x04		// w [1:0] 当输入为11时，对接口进行训练
#define USER_RESET_RTL	 			0x08		// w [0] 当输入为0时，对FPGA内部逻辑复位
#define USER_INIT_OK	 			0x0c		// w [0] 当输入为1时，指示上位机配置完毕
#define USER_TEXP0_GAP_LOW			0x10		// cmdw04 帧时间控制，每次更新此两个寄存器，必须要首先写入cmdw04，然后写入cmdw05。
#define USER_TEXP0_GAP_HIGH			0x14		// cmdw05

#define USER_CAMERA_MODE			0x18		// w [1:0] 00:idle 01:连拍模式（同cmdw09）10:拍照模式
#define USER_PHOTO_MODE				0x1c		// w [1:0] 00:内部电平宽度指令触发，可强制stop 01:内部电平宽度自动触发，可强制stop 10:内部电平宽度外部边沿触发，可强制stop 11:外部电平宽度触发，可强制stop
#define USER_TRIGGER 				0x20		// w [0] 指令触发信号
#define USER_ANOLOG_GAIN            0x67
#define HORIZONTAL_FLIPPING         0x01
#define USER_IMG_SEL 				0x24		// cmdw09 [0] 1:选择FPGA输出测试图像 0:输出实际图像
#define USER_STOP_EXP 				0x28		// w [0] 停止当前曝光
#define USER_TEXP0_EXP_LOW          0x2C		// w [0] exp [31:0]
#define USER_TEXP0_EXP_HIGH 		0x30		// w [0] exp [63:32]  unit 16.666ns at least 5  (1140+5)*16.666 = 19.
#define USER_CLR_TRIGGER            0x38		// w [0] 1 cler all count 0x90 0x94 0x9C
#define USER_DMA_RDY                0x3C		// w [0] 1 indicate soft is open dma driver ready when close dma must set to 0
#define USER_DMA_CNT                0x40		// w [0] 一次dma所需要接收的字节数，必须在初始化之前配置
#define USER_TRAINING_STATUS     	0x80		// r [1:0]接口处训练的状态,11表示训练成功
#define USER_R0                  	0x84		// r Reserved
#define USER_SENSOR_TEMP         	0x88		// r [7:0] snesor temp
#define USER_TRIGGER_STATUS         0x8C		// r [1:0] trigger status
#define USER_TRIGGER_CNT         	0x90		// r [31:0] all trigger signal count
#define USER_TRIGGER_SUCCESS_CNT    0x94		// r [31:0] all texp0 signal count
#define USER_REVEIVE_SUCCESS_CNT    0x98		// r [31:0] all receive fvld count
#define USER_REVEIVE_BYTE_CNT       0x9C		// r [31:0] all receive fvld count

typedef enum camera_mode{
    camera_mode_idle=0,
    camera_mode_video,
    camera_mode_photo
}user_camera_mode;

typedef enum photo_mode{
    trigger_mode_cmd=0,
    trigger_mode_free_run,
    trigger_mode_external_rising,
    trigger_mode_external_level
}user_photo_mode;

/*
 * note:map peripheral addr in linux system
*/
int sensor_user_setup(unsigned int baseAddr);

/*
 * note:reset the sensor,in this function it has 5 us delay.
*/
void sensor_user_reset();

/*
 * note:training the interface of FPGA lvds
*/
void sensor_user_training();

/*
 * note:reset the rtl logic in FPGA
*/
void sensor_user_rtl_reset();

/*
 * note:when all qt process are ready,notice the FPGA system can work with curren paramters.
 * 0:not ready;
 * 1:ready
*/
void sensor_user_init_status(unsigned int user_init_status);

/*
 * note:the gap of texp0 pulse,unit is 13.888ns.all range is 0 to 2^32
*/
void sensor_user_texp0_gap(unsigned int texp0_gap_high,unsigned int texp0_gap_low);

/*
 * note:the mode of camera
 * 0:camera_mode_idle
 * 1:camera_mode_video
 * 2:camera_mode_photo
*/
void sensor_user_camera_mode(unsigned int user_camera_mode);

/*
 * note:the mode of photo
 * 0:trigger_mode_idle
 * 1:trigger_mode_cmd
 * 2:trigger_mode_external_rising
 * 3:trigger_mode_external_level
*/
void sensor_user_photo_mode(unsigned int user_photo_mode);

/*
 * note:make the senor output only one image
*/
void sensor_user_trigger_once();

#endif // SENSOR_USER_H
